#!groovy
@Library("jenkinslib") _

//func from sharelibrary
def build=new org.devops.build()
def k8s=new org.devops.k8s()
// def deploy=new org.devops.deploy()
def tools=new org.devops.tools()
// def toemail=new org.devops.toemail()
//调用Jenkins中定义的选项参数 名称和Jenkins中定义的保持一致
//from jenkins 参数化构建变量
String buildType="${env.buildType}"
String buildshell="${env.buildshell}"
String deployHosts="${env.deployHosts}"
String srcURL="${env.SrcURL}"
String  branch="${env.branchName}"


// if ("${runOpts}"=="Gitlabpush"){
//     branch=branchName-"refs/heads/"
//     currentBuild.description= "Tigger by ${userName} ${branchName}"
//     gitlab.ChangeCommitStatus(projectId,commitSha,"running") //刚开始执行状态
// }

pipeline{
    agent {
        kubernetes { 
            cloud 'kubernetes'              // 对应 Jenkins 中配置的 Kubernetes 云名称
            inheritFrom 'jenkins-slave'  // 继承的 Pod 模板（可选）
            namespace 'default'      // 命名空间
            yaml k8s()            // 调用共享库生成 Pod YAML
        }
    }
    options {
        skipDefaultCheckout()  // 禁用隐式 Checkout
    }
    stages{
        stage("CheckOut"){
            steps{
                script{
                    println("${branch}")
                    tools.PrintMsg("获取代码","green")
                    checkout([$class: 'GitSCM', branches: [[name: "${branch}"]], 
                        extensions: [], 
                        userRemoteConfigs: [[credentialsId: 'gitee_registry_ssh', url: "${srcURL}"]]])
                }
            }
        }
        stage("Build"){
            steps{
                script{
                    //集成构建工具
                    container('mvn') {
                        tools.PrintMsg("代码打包","blue")
                        build.Build(buildType,buildshell)
                    }
                    //集成ansible工具
                   // deploy.AnsibleDeploy(deployHosts,"-m ping")
                }
            }
        }
    }
}
